package com.PMSys.Dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.PMSys.Demain.User;

public class UserDaoImp implements UserDao{

	private Connection conn;
	public UserDaoImp(Connection conn){
		this.conn=conn;
	}
	
	public User checkUser(User paramUser) {
		
		User user=null;
		//����sql���
		String sql="select * from user where username=? and password=?";
		if(paramUser.getUsername()=="" || paramUser.getUsername()==null){
			return null;
		}
		if(paramUser.getPassword()==null || paramUser.getPassword()==""){
			return null;
		}
		
		PreparedStatement pst=null;
		try {
			//�����������
			pst=conn.prepareStatement(sql);			
			//��Ӳ���			
			pst.setString(1, paramUser.getUsername());
			pst.setString(2, paramUser.getPassword());
		
			//ִ������
			ResultSet rs= pst.executeQuery();
			//�ѽ�����е�����ȡ����
			while(rs.next()){
				user=new User();
				user.setUsername(rs.getString("username"));
				user.setPassword(rs.getString("password"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}		
		return user;
	}

}
